<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>登入 - layuiAdmin</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/public/layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="/public/layuiadmin/style/admin.css" media="all">
  <link rel="stylesheet" href="/public/layuiadmin/style/login.css" media="all">
	<script src="/public/layuiadmin/jquery-1.11.2.min.js"></script>
	<style>
		.geetest_holder.geetest_wind {
			width: 100% !important;
		}
		.cr{
			text-align: center;
			color:white;
			font-size:14px;
			padding-top:30px;
		}
	</style>
</head>
<body>

  <div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">

    <div class="layadmin-user-login-main">
      <div class="layadmin-user-login-box layadmin-user-login-header">
        <h2>后台管理系统</h2>
        <p>layui 官方出品的单页面后台管理模板系统</p>
      </div>
      <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
        <div class="layui-form-item">
          <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>
          <input type="text" id="username"  lay-verify="required" placeholder="用户名" class="layui-input">
        </div>
        <div class="layui-form-item">
          <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
          <input type="password" id="password" lay-verify="required" placeholder="密码" class="layui-input">
        </div>
        <div class="layui-form-item">

			<div class="item" style="margin-top: 20px;">
				<div id="embed-captcha"></div>
				<div id="captcha" class="wait">
					<div class="loading" style="background: #fff;">
						<div class="bounce1"></div>
						<div class="bounce2"></div>
						<div class="bounce3"></div>
					</div>
				</div>
			</div>
<!--          <div class="layui-row">-->
<!--            <div class="layui-col-xs7">-->
<!--              <label class="layadmin-user-login-icon layui-icon layui-icon-vercode" for="LAY-user-login-vercode"></label>-->
<!--              <input type="text" name="vercode" id="LAY-user-login-vercode" lay-verify="required" placeholder="图形验证码" class="layui-input">-->
<!--            </div>-->
<!--            <div class="layui-col-xs5">-->
<!--              <div style="margin-left: 10px;">-->
<!--                <img src="https://www.oschina.net/action/user/captcha" class="layadmin-user-login-codeimg" id="LAY-user-get-vercode">-->
<!--              </div>-->
<!--            </div>-->
<!--          </div>-->
        </div>
        <div class="layui-form-item">
<!--          <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="login-submit">登 入</button>>-->
			<button class="layui-btn layui-btn-fluid" id="login">登 入</button>
        </div>
      </div>
    </div>

  </div>

  <script src="/public/layuiadmin/layui/layui.js"></script>
  <link rel="stylesheet" type="text/css" href="/public/layuiadmin/style/geetest.css">
  <script src="/public/captcha/jigsaw.js"></script>
  <script src="/public/captcha/gt.js"></script>
  <script>
  layui.config({
    base: '/public/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'user'], function(){
    var $ = layui.$
    ,setter = layui.setter
    ,admin = layui.admin
    ,form = layui.form
    ,router = layui.router()
    ,search = router.search;
    form.render();

      //登录
      $(function () {
          var handlerEmbed = function (captchaObj) {
              $("#login").click(function(){
                  var username = $("#username").val();
                  if(username=='')
                  {
                      layer.msg('用户名不能为空', {icon: 2});
                      return false;
                  }
                  var password = $("#password").val();
                  if(password=='')
                  {
                      layer.msg('密码不能为空', {icon: 2});
                      return false;
                  }
                  var validate = captchaObj.getValidate();
                  if (!validate) {
                      layer.msg('请先完成验证！');
                      captchaObj.reset(); // 调用该接口进行重置
                      return false;
                  } else {
                      $.ajax({
                          url: '/public/captcha/VerifyLoginServlet.php',
                          type: 'POST',
                          dataType: 'json',
                          data: {
                              geetest_challenge: $('input[name=geetest_challenge]').val(),
                              geetest_validate: $('input[name=geetest_validate]').val(),
                              geetest_seccode: $('input[name=geetest_seccode]').val(),
                          },
                          success: function (data) {
                              if (data.status == 'success') {
                                  $.ajax({
                                      type: "POST",
                                      url: "/admin/Login/login",
                                      data: {username: username, password: password},
                                      dataType: "json",
                                      success: function (res) {
                                          if (res.code == 0) {
                                              layer.msg(res.content, {icon: 2});
                                              return false;
                                          } else {
                                              layer.msg(res.content, {
                                                  offset: '15px'
                                                  , icon: 1
                                                  , time: 1000
                                              }, function () {
												  location.href = '/admin/Index/index'; //主页
                                              });
                                          }
                                      }
                                  });
                              } else {
                                  layer.msg('安全认证失败！');
                                  captchaObj.reset(); // 调用该接口进行重置
                              }
                          }
                      });
                  }
                  return false;
              })
              //});
              // 将验证码加到id为captcha的元素里，同时会有三个input的值：geetest_challenge, geetest_validate, geetest_seccode
              captchaObj.appendTo("#embed-captcha");
              captchaObj.onReady(function () {
                  var timer = setInterval(fn1, 50);
                  $(".wait")[0].className = "hide";
              });
              //});
          }
          $.ajax({
              // 获取id，challenge，success（是否启用failback）
              url: "/public/captcha/StartCaptchaServlet.php?t=" + (new Date()).getTime(), // 加随机数防止缓存
              type: "get",
              dataType: "json",
              success: function (data) {
                  // 使用initGeetest接口
                  // 参数1：配置参数
                  // 参数2：回调，回调的第一个参数验证码对象，之后可以使用它做appendTo之类的事件
                  initGeetest({
                      gt: data.gt,
                      challenge: data.challenge,
                      new_captcha: data.new_captcha,
                      product: "embed", // 产品形式，包括：float，embed，popup。注意只对PC版验证码有效
                      offline: !data.success // 表示用户后台检测极验服务器是否宕机，一般不需要关注
                      // 更多配置参数请参见：http://www.geetest.com/install/sections/idx-client-sdk.html#config
                  }, handlerEmbed);
              }
          });
          //删除验证码技术支持
          function fn1() {
              if ($('.geetest_logo').length != 0) {
                  $('.geetest_logo').remove();
              }
              if ($('.geetest_copyright').length != 0) {
                  $('.geetest_copyright').remove();
              }
              if ($('.geetest_feedback').length != 0) {
                  $('.geetest_feedback').remove();
              }
              if ($('.geetest_success_logo').length != 0) {
                  $('.geetest_success_logo').remove();
              }

              $('.geetest_fullpage_click_box').attr('style', 'width: 253px;top: -132px;left: -8px;');
              $('.geetest_holder').attr('style', 'width: 253px;');
              $('.geetest_fullpage_pointer').attr('style', 'display: none;');
          }
      })
  });
  </script>
</body>
</html>
